<template>
  <view>
    <view v-for="(measures, measuresIndex) in measuresData" :key="measuresIndex">
      <view class="flex-tr analyse-table" style="border-left: 1px solid #124264; background: #f1f1f1">
        <view class="flex-td--header" style="width: 44px">序号</view>
        <view class="flex-td--value">安全措施</view>
        <view class="flex-td--header" style="width: 70px">是否涉及</view>
        <view class="flex-td--header" style="width: 190px">确认人</view>
      </view>

      <view
        v-for="(item, index) in measures.ticketReviewContent"
        :key="index"
        class="flex-tr analyse-table"
        style="border-left: 1px solid #124264"
      >
        <view class="flex-td--header" style="width: 44px">{{ index + 1 }}</view>
        <view
          v-if="index + 1 === measures.ticketReviewContent.length"
          class="flex-td--value"
          style="display: block; border-right: 1px solid #124264"
        >
          <view>其他安全措施：{{ item.remark }}</view>
          <view>编制人：{{ item.userName }}</view>
        </view>
        <template v-else>
          <view class="flex-td--value">
            <view>
              <template v-for="con in item.content">
                <text v-if="isVariable(con)">{{ item[con] }}</text>
                <text v-else>{{ con }}</text>
              </template>
            </view>
          </view>
          <view class="flex-td--header" style="width: 70px">
            <view v-if="[1, 0].includes(item.isInvolve)">
              <text v-if="item.isInvolve === 1">是</text>
              <text v-if="item.isInvolve === 0">否</text>
            </view>
          </view>
          <view class="flex-td--header text-center" style="width: 190px; display: block">
            <image
              v-for="imgItem in measures.signatureUrls"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, measures.signatureUrls)"
            ></image>
          </view>
        </template>
      </view>
    </view>

    <view class="flex-tr">
      <view class="flex-td--label" style="width: 110px">安全交底人</view>
      <view class="flex-td--value" style="display: block">
        <image
          v-for="imgItem in disclosureSignatures"
          :key="imgItem"
          :src="`${staticUrl}${imgItem}`"
          mode="aspectFill"
          class="signature__img"
          @click="handlePreviewImage(`${staticUrl}${imgItem}`, disclosureSignatures)"
        ></image>
      </view>
      <view class="flex-td--label" style="width: 110px">接受交底人</view>
      <view class="flex-td--value" style="display: block; border-right: 1px solid #124264">
        <image
          v-for="imgItem in acceptDisclosureSignatures"
          :key="imgItem"
          :src="`${staticUrl}${imgItem}`"
          mode="aspectFill"
          class="signature__img"
          @click="handlePreviewImage(`${staticUrl}${imgItem}`, acceptDisclosureSignatures)"
        ></image>
      </view>
    </view>
    <template v-if="ticket.workTypeFlag === specialWorkTypeEnum.FIRE">
      <view class="flex-tr">
        <view class="flex-td--label" style="width: 110px">监护人</view>
        <view class="flex-td--value" style="display: block; border-right: 1px solid #124264">
          <template v-if="guardianSignatures.length">
            <image
              v-for="imgItem in guardianSignatures"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, guardianSignatures)"
            ></image>
          </template>
        </view>
      </view>
    </template>

    <view class="tr-signature" v-for="(item, index) in approvalData" :key="`c${index}`">
      <view>{{ replaceNodeName(item) }}</view>
      <view v-for="(item2, index2) in item.data" :key="`d${index2}`">
        <view class="flex">
          <view style="line-height: 40px; margin-right: 20px">
            {{ item2.reviewDescription }}
          </view>
          <view>
            <image
              v-for="imgItem in item2.signatureUrls"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, item2.signatureUrls)"
            ></image>
          </view>
        </view>
        <view>
          {{ dateFormat(item2.createTime, 'YYYY 年 MM 月 DD 日 HH 时 mm 分') }}
        </view>
      </view>
    </view>

    <view class="tr-signature" v-for="(item, index) in checkData" :key="`e${index}`">
      <view>{{ replaceNodeName(item) }}</view>
      <view v-for="(item2, index2) in item.data" :key="`f${index2}`">
        <view class="flex">
          <view style="line-height: 40px; margin-right: 20px">
            {{ item2.reviewDescription }}
          </view>
          <view>
            <image
              v-for="imgItem in item2.signatureUrls"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, item2.signatureUrls)"
            ></image>
          </view>
        </view>
        <view>
          {{ dateFormat(item2.createTime, 'YYYY 年 MM 月 DD 日 HH 时 mm 分') }}
        </view>
      </view>
    </view>

    <view class="tr-signature" v-for="(item, index) in operationData" :key="`g${index}`">
      <view>{{ replaceNodeName(item) }}</view>
      <view v-for="(item2, index2) in item.data" :key="`ba${index2}`">
        <view class="flex">
          <view style="line-height: 40px; margin-right: 20px">
            {{ item2.reviewDescription }}
          </view>
          <view>
            <image
              v-for="imgItem in item2.signatureUrls"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, item2.signatureUrls)"
            ></image>
          </view>
        </view>
        <view>
          {{ dateFormat(item2.createTime, 'YYYY 年 MM 月 DD 日 HH 时 mm 分') }}
        </view>
      </view>
    </view>

    <view class="tr-signature" v-for="(item, index) in completeData" :key="`bx${index}`">
      <view>完工验收</view>
      <view v-for="(item2, index2) in item.data" :key="`vc${index2}`">
        <view class="flex">
          <view style="line-height: 40px; margin-right: 20px">
            {{ item2.reviewDescription }}
          </view>
          <view>
            <image
              v-for="imgItem in item2.signatureUrls"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="signature__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, item2.signatureUrls)"
            ></image>
          </view>
        </view>
        <view>
          {{ dateFormat(item2.createTime, 'YYYY 年 MM 月 DD 日 HH 时 mm 分') }}
        </view>

        <view v-for="(item2, index2) in item.data" :key="index2" class="mt-12">
          <view>{{ item2.content }}</view>
          <view>
            <image
              v-for="imgItem in item2.uploadUrl"
              :key="imgItem"
              :src="`${staticUrl}${imgItem}`"
              mode="aspectFill"
              class="complete__img"
              @click="handlePreviewImage(`${staticUrl}${imgItem}`, item2.uploadUrl)"
            ></image>
          </view>
        </view>
      </view>
    </view>

    <view class="tr-signature" v-for="(item, index) in cancelInfo" :key="`quxiao${index}`">
      <view>{{ item.creator }}取消作业</view>
      <view>取消原因：{{ item.cancelReason }}</view>
      <view>取消时间：{{ dateFormat(item.createTime, 'YYYY 年 MM 月 DD 日 HH 时 mm 分') }}</view>
    </view>
  </view>
</template>
<script>
import { specialWorkTypeEnum } from '@/utils/constant'
import { staticUrl } from '@/config'
import ticketTableMixin from './ticketTableMixin'
import dayjs from 'dayjs'
export default {
  name: 'ExamineTable',
  mixins: [ticketTableMixin],
  props: {
    inspect: {
      type: Object,
      default: () => ({})
    },
    signatures: {
      type: Array,
      default: () => []
    },
    cancelInfo: {
      type: Array,
      default: () => []
    },
    ticketContent: {
      type: Object,
      default: () => ({})
    },
    ticket: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {},
  data() {
    return {
      specialWorkTypeEnum,
      staticUrl
    }
  },
  methods: {
    dateFormat(date, format) {
      return dayjs(date).format(format)
    },
    /**
     * @description 处理节点名称
     */
    replaceNodeName(item) {
      let { ticketNodeName } = item
      if (ticketNodeName.indexOf(':') > -1) {
        const arr = ticketNodeName.split(':')
        return arr[arr.length - 1]
      } else if (ticketNodeName.indexOf('：') > -1) {
        const arr = ticketNodeName.split('：')
        return arr[arr.length - 1]
      }
      return ticketNodeName
    },

    /**
     * @description 判断是不是自己定义的变量
     */
    isVariable(val) {
      return /^\$variable/.test(val)
    }
  }
}
</script>
<style lang="scss" scoped>
@import './style.scss';
</style>
